<?php
include("../db_connect.php");
?>


<script>
var limiter = 0;
$(document).ready(function () {

$("#addpictures").click(function () {
		if(limiter <=6){
		
		var a = '</br> <div><img id="img_prev'+limiter+'" src="#"/></div><input type="file" name="image[]" id="image" onchange="readURL(this);"></br>'
		
		$("#addmorepicture").append(a);
		
		}
		else{
		alert("you can only upload 6 picture");
		}
		return false;
		
	});
$("#abrand").change(function () {
		var id = $(this).attr("value");
		var model="model";
		$("#amodel").empty().load("admin/selection.php?command="+model +"&modelid="+id);
	
	});
	
$("#registerButton").click(function () {

var opttype = $("#types");
var optbrand = 	$("#abrand");
var model = $("#amodel");
var name = $("#name");
var description = $("#description");
var condition = $("#conditions");
var fuel = $("#fuel");
var transmission = $("#transmission");
var year = $("#year"); 
var price = $("#price");
var quantity = $("#quantity");

	
	if(opttype.val() ==  "Select" || opttype.val() == "0"){
	alert(opttype.val());
	alert("Select a type");
	opttype.focus();
	return false;
	}
	else if(optbrand.val() ==  "Select" || optbrand.val() ==  "0"){
	alert("Select a brand");
	optbrand.focus();
	return false;
	}
	else if(model.val() ==  "Select" || model.val() ==  ""){
	alert("Select a model");
	model.focus();
	return false;
	}
	else if(name.val() ==  "" || name.val() ==  " "){
	alert("Please input a name");
	name.focus();
	return false;
	}
	else if(description.val() ==  "" || description.val() ==  " "){
	alert("Please input your description");
	description.focus();
	return false;
	}
	else if(condition.val() ==  "Select Condition" || condition.val() ==  "0"){
	alert("Select a condition");
	condition.focus();
	return false;
	}
	else if(fuel.val() ==  "Select Fuel" || fuel.val() ==  "0"){
	alert("Select a fuel type");
	fuel.focus();
	return false;
	}
	else if(transmission.val() ==  "Select Transmission"|| transmission.val() ==  "0"){
	alert("Select transmission");
	transmission.focus();
	return false;
	}
	else if(year.val() ==  "Select" || year.val() ==  "0"){
	alert("Select year");
	year.focus;
	return false;
	}
	else if(price.val() ==  "" || price.val() == " "){
	alert("Please input quantity");
	price.focus();
	return false;
	}
	else if(isNaN(price.val())){
	alert("Price only accept No.");
	price.focus();
	return false;
	}
	else if(quantity.val() ==  ""|| quantity.val() ==  " "){
	alert("Please input quantity");
	quantity.focus();
	return false;
	}
	else if(isNaN(quantity.val())){
	alert("Price only quantity No.");
	quantity.focus();
	return false;
	}
	else{
	 return true;
	}
	

});	

});

function readURL(input) {
	var b = '#img_prev'+limiter;
	
	if (input.files && input.files[0]) {
		var reader = new FileReader();
		reader.onload = function (e) {
			$(b).attr('src', e.target.result).width(300).height(120);
			limiter++;
		};
			reader.readAsDataURL(input.files[0]);
	}
}
	
	
	
</script>

<h4 style="color:white"><font>Add New Auto</font></h4>
<div id="auto" class="auto">
								<div id="wrapper">
										<div id="steps">
											<form id="formElem" name="formElem" action="profile/tae.php" method="post" enctype="multipart/form-data">

												<fieldset class="step">
													<legend>Item Name</legend>
													<p>
														<label for="types">Type</label>
														<select id="types" value="types"  name="types">
														<?php 
															$sql = mysql_query("SELECT * FROM tbltypes");
															$opt2 = '<option id="opttype" name="none" value="0">Select</option> ';
															
															while($row = mysql_fetch_array($sql) ){
																$opt2 .= '<option id="opttype" value="'.$row["types"].'" >'.$row["types"].'</option>';
															}
															echo $opt2;
														?>
														</select>
														
														
													</p>
													<p>
														<label for="brand">Brand</label>
														<select id="abrand" value="brand" name="brand">
														<?php 
															$sql = mysql_query("SELECT * FROM tblbrand");
															$opt = '<option id="optbrand" name="none" value="0">Select</option> ';
															while($row = mysql_fetch_array($sql) ){
																$opt .= '<option id="optbrand" name="'.$row["brand"].'" value="'.$row["id"].'" >'.$row["brand"].'</option>';
															}
															echo $opt;
														?>
														</select>
													</p>
													<p>
														<label for="Model">Model</label>
														<select id="amodel" value="model" name="model">
														
														</select>
														
													</p>
												
													<p>
														<label for="Name">Name</label>
														<input type="text" id="name" name="name" AUTOCOMPLETE=OFF />
													   
													</p>
												</fieldset>
												
												
												<fieldset class="step">
													<legend>Description</legend>
													<p>
														<label for="description">Description</label>
														<textarea style="width: 600px; height: 123px;" id="description" value="description" name="description"></textarea>
													</p>
													
													<p>
														<label for="Conditions">Condition</label>
														 <select id="conditions" value="conditions" name="conditions">
															<option  value="0" >Select Condition</option>
															<option  value="BrandNew" >BrandNew</option>
															<option  value="2ndHand">2ndHand</option>
														</select>
													</p>
													<p>
													  <label for="fuel" id = "fuel">Fuel</label>
														<select id = "fuel" name="fuel">
															<option value="0">Select Fuel</option>
															<option value="Gasoline">Gasoline</option>
															<option value="Diesel">Diesel</option>
															<option value="Lpg">LPG</option>
															<option value="Hybrid">Hybrid</option>
															<option value="Electric">Electric</option>
														</select>
													</p>
													
												</fieldset>
												
												<fieldset class="step">
													<legend>Description</legend>
													<p>
													 <label for="transmission" id = "transmission">Transmission</label>
														<select id = "transmission" name="transmission">
															<option value="0">Select Transmission</option>
															<option value="Manual">Manual</option>
															<option value="Automatic">Automatic</option>
														</select>
													</p>
													<p>
														<label for="year">Year</label>
														<select id="year" name="year">
															<option value="0">Select</option>
															<option>2006</option>
															<option>2007</option>
															<option>2008</option>
															<option>2009</option>
															<option>2010</option>
															<option>2011</option>
															<option>2012</option>
														</select>
													</p>
													<p>
														<label for="price">Price</label>
														<input id="price" name="price" type="number" AUTOCOMPLETE=OFF />
													</p>
													<p>
														<label for="quantity">Quantity</label>
														<input id="quantity" name="quantity" type="number" AUTOCOMPLETE=OFF />
													</p>
													
												</fieldset>
												<fieldset class="step">
													<legend>Image</legend>
													<div id="addmorepicture">
														
													</div>
													<p>
														<button id="addpictures">Add picture</button>
													</p>
												</fieldset>
												<fieldset class="step">
													<legend>Confirm</legend>
													<p>
														Please fill up all the missing fields before you proceed
													</p>
													<p class="submit">
														<button id="registerButton" type="submit" name = "submit">Add New Auto</button>
													</p>
												</fieldset>
											</form>
										</div>
										
									</div>

							</div
							